/******************************************************************************
             Copyright (c) 1999 Unigraphics Solutions, Inc.
                       Unpublished - All Rights Reserved

*******************************************************************************/
/*

The following example requires a blank, open part. The code creates
a surface from 16 points.

*/
#include "StdAfx.h"
#include <stdio.h>
#include <uf.h>
#include <uf_modl.h>
#include "Select.h"
#include <uf_ui.h>
#define UF_CALL(X) (report( __FILE__, __LINE__, #X, (X)))
static int report( char *file, int line, char *call, int irc)
{
  if (irc)
  {
     char    messg[133];
     printf("%s, line %d:  %s\n", file, line, call);
     (UF_get_fail_message(irc, messg)) ?
       printf("    returned a %d\n", irc) :
       printf("    returned error %d:  %s\n", irc, messg);
  }
  return(irc);
}
static void do_ugopen_api(void)
{
	CSelect ss;
	tag_t face;
	char msg[132];

	logical is_smooth;
	double uv_min_max[4];

	int type, norm_dir;
	double point[3], dir[3], box[6], radius, rad_data;
	double param[2], u1[3], v1[3], u2[3], v2[3], unit_norm[3], radii[2];

	UF_UI_open_listing_window();
	ss.SelectSurface(&face);

	UF_MODL_ask_face_smoothness(face, &is_smooth);
	sprintf(msg, "is_smooth:%d\n", is_smooth);
	UF_UI_write_listing_window(msg);

	UF_MODL_ask_face_uv_minmax(face, uv_min_max);
	sprintf(msg, "uv_min_max:\nu_min:%.3f\nu_max:%.3f\nv_min:%.3f\nv_max:%.3f\n", 
		uv_min_max[0], uv_min_max[1], uv_min_max[2], uv_min_max[3]);
	UF_UI_write_listing_window(msg);
	
	UF_MODL_ask_face_data(face, &type, point, dir, box, &radius, &rad_data, &norm_dir);
	sprintf(msg, "face type:%d\n", type);
	UF_UI_write_listing_window(msg);
	sprintf(msg, "box:\n");
	UF_UI_write_listing_window(msg);
	sprintf(msg, "xmin:%.3f\txmax:%.3f\n", box[0], box[3]);
	UF_UI_write_listing_window(msg);
	sprintf(msg, "ymin:%.3f\tymax:%.3f\n", box[1], box[4]);
	UF_UI_write_listing_window(msg);
	sprintf(msg, "zmin:%.3f\tzmax:%.3f\n", box[2], box[5]);
	UF_UI_write_listing_window(msg);

	param[0] = 0.5;
	param[1] = 0.5;
	UF_MODL_ask_face_props(face, param, point, u1, v1, u2, v2, unit_norm, radii);
	sprintf(msg, "The point at (%.3f, %.3f) is:\n%.3f,%.3f,%.3f\n", 
		param[0], param[1], point[0], point[1], point[2]);
	UF_UI_write_listing_window(msg);
	sprintf(msg, "unit_norm:%.3f\t%.3f\t%.3f\n", unit_norm[0], unit_norm[1], unit_norm[2]);
	UF_UI_write_listing_window(msg);
}
/*ARGSUSED*/
void ufusr(char *param, int *retcode, int param_len)
{
  if (!UF_CALL(UF_initialize()))
  {
    do_ugopen_api();
    UF_CALL(UF_terminate());
  }
}
int ufusr_ask_unload(void)
{
  return (UF_UNLOAD_IMMEDIATELY);
}


